﻿namespace Web.Control.WWW.Files
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Lx.Web.Common.ControlsUI;
    using System.Collections;
    using BLF.WWW_WWW.Files;

    /// <summary>
    /// Topmembers 的摘要说明
    /// </summary>
    public class Topmembers : BaseControl
    {
        /// <summary>
        /// 学习语言
        /// </summary>
        protected string LL = "";
        /// <summary>
        /// 使用语言
        /// </summary>
        protected string BL = "";
        
        protected Repeater rptTopMember;
        protected Repeater rptPopFile;
        protected Repeater rptLastestF;

        protected override void OnLoad(EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request["LL"]))
            {
                LL = Request["LL"].ToLower() == "all" ? "" : Request["LL"];
                HttpCookie llCookie = new HttpCookie("italkiLearn", Request["LL"]);
                Response.Cookies.Add(llCookie);
            }
            else if(Request.Cookies["italkiLearn"] != null)
            {
                LL = Request.Cookies["italkiLearn"].Value.ToLower() == "all" ? "" : Request.Cookies["italkiLearn"].Value;
            }
            if (!string.IsNullOrEmpty(Request["BL"]))
            {
                BL = Request["BL"].ToLower() == "all" ? "" : Request["BL"];
                HttpCookie blCookie = new HttpCookie("italkiSpeak", Request["BL"]);
                Response.Cookies.Add(blCookie);
            }
            else if (Request.Cookies["italkiSpeak"] != null)
            {
                BL = Request.Cookies["italkiSpeak"].Value.ToLower() == "all" ? "" : Request.Cookies["italkiSpeak"].Value;
            }
            ArrayList arrList = Files.GetTopMembers(LL, BL);
            //标题
            if (LL != "" && BL != "")
            {
                this.DynamicTitle = GetText("SF524", new string[] { GetLanguageText(LL), GetLanguageText(BL) });
                this.DynamicKeywords = GetText("SF525", new string[] { GetLanguageText(LL), GetLanguageText(BL) });
                this.DynamicDescription = GetText("SF526", new string[] { GetLanguageText(LL), GetLanguageText(BL) });
            }
            else
            {
                this.DynamicTitle = GetText("SF521");
                this.DynamicKeywords = GetText("SF522");
                this.DynamicDescription = GetText("SF523");
            }

            if (arrList != null)
            {
                if (rptTopMember != null)
                {
                    rptTopMember.DataSource = arrList[0];
                    rptTopMember.DataBind();
                }
                if (rptPopFile != null)
                {
                    rptPopFile.DataSource = arrList[1];
                    rptPopFile.DataBind();
                }
                if (rptLastestF != null)
                {
                    rptLastestF.DataSource = arrList[2];
                    rptLastestF.DataBind();
                }
            }
            else {
                Response.End();
                return;
            }
        }
    }
}
